package com.itwill.ecom.boardQnA;

import java.util.List;

import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository("boardQnAService")
public class BoardQnAServiceImpl implements BoardQnAService{
	
	/////객체 생성 및 생성자,set,get/////
	@Autowired
	private BoardQnADao boardQnADao;
	
	public BoardQnAServiceImpl() {
		System.out.println("BoardQnAServiceImpl() 생성");
	}

	public BoardQnAServiceImpl(BoardQnADao boardQnADao) {
		
		this.boardQnADao = boardQnADao;
	}

	public BoardQnADao getBoardQnADao() {
		return boardQnADao;
	}
 
	
	public void setBoardQnADao(BoardQnADao boardQnADao) {
		this.boardQnADao = boardQnADao;
	}

	//// 게시글 작성 ////
	@Override
	public int createBoardQnA(BoardQnABeans boardQnABeans) {
		int result=-1;
		try{
			result=boardQnADao.createBoardQnA(boardQnABeans);
			result=1;
		}catch(Exception e){
			String msg=e.getMessage();
			System.out.println(msg);
			
		}
		return result;
	}
	
	//// 게시글 모두 호출 ////
	@Override
	public List<BoardQnABeans> getAllBoardQnA() {
		List<BoardQnABeans> selectQnABoard = null;
		try{
		selectQnABoard=boardQnADao.getAllBoardQnA();
		}catch(Exception e){
			String msg=e.getMessage();
			System.out.println(msg);
			
		}
		return selectQnABoard;
	}

	//// 내 게시물 검색 ////
	@Override
	public List<BoardQnABeans> getByIdBoardQnA(String qnaboard_id) {
		List<BoardQnABeans> selectMyQnABoard=null;
		try{
			selectMyQnABoard=boardQnADao.getById(qnaboard_id);
		}catch(Exception e){
			String msg=e.getMessage();
			System.out.println(msg);
		}
		return selectMyQnABoard;
	}
	
	//// 게시글 수정 ////
	@Override
	public int updateBoardQnA(BoardQnABeans boardQnABeans) {
		int result= -1;
		try{
			result=boardQnADao.updateBoardQnA(boardQnABeans);
			result=1;
		}catch(Exception e){
			String msg=e.getMessage();
			System.out.println(msg);
		}
		return result;
	}
	
	//// 게시글 삭제 ////
	@Override
	public int deleteBoardQnA(int qnaboard_no) {
		int result=-1;
		try{
			result=boardQnADao.deleteBoardQnA(qnaboard_no);
		}catch(Exception e){
			String msg=e.getMessage();
			System.out.println(msg);
		}
		return result;
	}
	//// 게시물 클릭 ////
	@Override
	public BoardQnABeans getByNoBoardQnA(int qnaboard_no) {
		BoardQnABeans qnaboard = null;
		try{
		qnaboard=boardQnADao.getByNo(qnaboard_no);
		}catch(Exception e){
			String msg=e.getMessage();
			System.out.println(msg);
		}
		return qnaboard;
		
	}
	
	
	

}
